package com.edu.web.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.edu.service.UserBackgroundService;
import com.edu.service.impl.UserBackgroundServiceImpl;

/**
 * Servlet implementation class UserDeleteServlet
 */
@WebServlet("/UserDeleteServlet")
public class UserDeleteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UserDeleteServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		UserBackgroundService userBackService = new UserBackgroundServiceImpl();
		int userId = Integer.parseInt(request.getParameter("userId"));
		String getTable=request.getParameter("tableName");
		String getTableId=request.getParameter("tableId");
		userBackService.deleteId(userId,getTableId,getTable);
		
		if(getTable.equals("users")) {
			response.sendRedirect("FenYeUserServlet?currentPageNum=1&pageSize=5");
		}else {
			response.sendRedirect("FenYeShopServlet?currentPageNum=1&pageSize=5");
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
